SHARED_FLAGS:=-shared -fPIC

CFLAGS+=-g

.PHONY:all

output:=$(shell mkdir -p output)

_all=demo $(patsubst %.c, output/%.so, $(wildcard lib*.c)) $(output)

all:$(_all)

demo: demo.c
	$(CC) $(CFLAGS) $< -o $@ -ldl

output/libtest1.so:libtest1.c
	$(CC) $(CFLAGS) $(SHARED_FLAGS) $< -o $@ -nostartfiles

output/libtest2.so:libtest2.c
	$(CC) $(CFLAGS) $(SHARED_FLAGS) $< -o $@ -Wl,-init=my_init,-fini=my_fini -e my_start

output/libtest3.so:libtest3.c
	$(CC) $(CFLAGS) $(SHARED_FLAGS) $< -o $@ -Wl,-init=my_init,-fini=my_fini -e my_start

output/libtest4.so:libtest4.c
	$(CC) $(CFLAGS) $(SHARED_FLAGS) $< -o $@ -e my_start

.PHONY:clean

clean:
	$(RM) $(_all)

